Skip to content
  • 0 Votes
    4 Posts
    7k Views
    S

    All,
    Yes I am sorry for the mix up . Late and frustrated.

    Anyway I did a lot of refactoring based on the feedback and appear to have one glaring problem. Previously, my KeyData class was being instantiated without me knowing it by QML. Now the attempt is to instantiate from C++. I have a drawer control in QML that is a bunch of nav buttons. The model for this is in C++ as a QList of *KeyData.
    So my drawer is now unpopulated and in the debug window the error is:
    QMetaProperty::read: Unable to handle unregistered datatype 'QQmlListProperty<KeyData>' for property 'QmlMain::KeyModel'. Previously that was not an issue. I think a complication at least for me is that key and Nav are defined as structures and I've had to prepend 'struct' everywhere they were used.

    struct Key { QString id; QString type; QString title; QString icon; QString target; }; struct Nav { QString id; QString title; QString source; QList <Key> keys; QList <int> milestones; };

    In my main class header that is now a exposed to QML as a context property, I have:

    Q_PROPERTY (QQmlListProperty<KeyData> KeyModel READ readKeyModel NOTIFY keyModelChanged) ... //model for model/view of keys void writeKeyModel(); QQmlListProperty<KeyData> readKeyModel(); QList<KeyData *> getKeyModel() const; void setKeyModel(const QList<KeyData *> &keyModel); ... QList<KeyData *> _keyModel;

    In my main class imlementation I have:

    QList<KeyData *> QmlMain::getKeyModel() const { return _keyModel; } void QmlMain::setKeyModel(const QList<KeyData *> &keyModel) { _keyModel = keyModel; } QQmlListProperty<KeyData> QmlMain::readKeyModel() { return QQmlListProperty<KeyData>(this, _keyModel); } void QmlMain::writeKeyModel() { _keyModel.clear(); Key key; foreach (key, this->_navRecord.keys) { _keyModel.append(new KeyData(key.id, key.type, key.title, key.icon, key.target)); } qDebug() << "setKeyModel"; // emit this->keyModelChanged(); }

    In QML I have

    //nav drawer Drawer { id: drawer width: Math.min(window.width, window.height) / 3 * 2 height: window.height background: Rectangle { //add fill to drawer anchors.fill: parent color: "white" } ListView { id: listView currentIndex: -1 anchors.fill: parent model: QML_MAIN.KeyModel //c++ model

    Thank you for any help you are kind enough to provide